<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@taglib prefix="a4j" uri="http://richfaces.org/a4j"%>
<%@taglib prefix="rich" uri="http://richfaces.org/rich"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<%--
    This file is an entry point for JavaServer Faces application.
--%>
<f:view>
    <html>
        <head>
            <link rel="stylesheet" type="text/css" href="/NamibiaMedicalControl/style.css" title="Variant Stream" media="screen,projection" >
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title><h:outputText value="Registra paziente"/></title>
        </head>
        <body>

            <div id="wrapper">
                <div id="logo">
                    <h1>Namibia medical control</h1>
                    <p><h:outputText value="#{msg.sottotitolo}"/></p>
                </div>
                <hr>
                <!-- end #logo -->
                <div id="header">
                    <div id="menu">
                        <ul>
                            <li><a href="/NamibiaMedicalControl/faces/home.jsp" class="first" >Home</a></li>           
                        </ul>
                    </div>
                    <!-- end #menu -->
                    <div id="search">
                        <div id="search-text">
                            <h:panelGroup rendered="#{loginBean.subview != null}">
                                <jsp:include page="${loginBean.subview}" />
                            </h:panelGroup>
                        </div>
                    </div>
                    <!-- end #search -->
                </div>
                <!-- end #header -->
                <!-- end #header-wrapper -->
                <div id="page">
                    <div id="page-bgtop">
                        <div id="content">
                            <div class="post">
                                <h2 class="title"><h:outputText value="#{msg.registra}"/></h2>
                                <p class="meta">Registra un paziente</p>
                                <div class="entry">
                                    <a4j:form>
                                        <a4j:keepAlive beanName="suggestionBoxBean"/>
                                        <a4j:keepAlive beanName="pazientiACBean"/>
                                        <h:inputText id="input_person" value="#{suggestionBoxBean.input}"/>
                                        <rich:suggestionbox  for="input_person"
                                                             suggestionAction="#{pazientiACBean.autocompletePaziente}"
                                                             fetchValue="#{result.id} #{result.nome} #{result.cognome}"
                                                             var="result"
                                                             height="200"
                                                             width="300" >

                                            <h:column>
                                                <h:outputText value="#{result.id}"/>
                                            </h:column>
                                            <h:column>
                                                <h:outputText value="#{result.nome}" />
                                            </h:column>
                                            <h:column>
                                                <h:outputText value="#{result.cognome}"/>
                                            </h:column>
                                            <h:column>
                                                <h:outputText value="#{result.dataNascita}"/>
                                            </h:column>
                                        </rich:suggestionbox>
                                        <a4j:commandButton type="submit" value="Compila" action="#{suggestionBoxBean.action()}" reRender="res,fu"/>
                                        <h:selectBooleanCheckbox value="#{suggestionBoxBean.birth}">
                                            <a4j:support event="onchange" reRender="res,fu"/>
                                        </h:selectBooleanCheckbox>
                                        <h:outputText value="Clicca qui per aggiungere un nuovo nato"/>
                                        <h:panelGroup id = "res">
                                            <br>
                                            <h:outputText styleClass="error" rendered="#{suggestionBoxBean.error}" value="C'è un errore nell'inserimento dei dati, hai settato te stesso in qualche parametro?"/>
                                            <h:panelGroup rendered="#{suggestionBoxBean.render||suggestionBoxBean.birth}">
                                                <h:outputText value="I campi indicati con * sono obbligatori!"/>
                                                <table width="100%">
                                                    <tr>
                                                        <td>
                                                            <h:panelGroup id = "foto">
                                                                <h:graphicImage url="#{suggestionBoxBean.foto}" width="210px" height="210px"/>
                                                            </h:panelGroup>
                                                        </td> 
                                                        <td>
                                                            <table width="100%">
                                                                <tr>
                                                                    <td><b>Nome: </b></td>
                                                                    <td>
                                                                        <h:outputText value="#{suggestionBoxBean.nome} #{suggestionBoxBean.cognome}" rendered ="#{suggestionBoxBean.render}"/>
                                                                        <h:inputText id ="name" value="#{suggestionBoxBean.nome}" required = "true" rendered = "#{suggestionBoxBean.birth}"/>
                                                                        <h:message styleClass="error" for="name"/>
                                                                    </td>
                                                                </tr>
                                                                <h:panelGroup rendered = "#{suggestionBoxBean.birth}">
                                                                    <tr>
                                                                        <td><b>Cognome: </b></td>
                                                                        <td>
                                                                            <h:inputText id ="surname" value="#{suggestionBoxBean.cognome}" required = "true"/>
                                                                            <h:message styleClass="error" for="surname"/>
                                                                        </td>
                                                                    </tr>
                                                                </h:panelGroup>
                                                                <tr>
                                                                    <td><b>*Password: </b></td>
                                                                    <td>
                                                                        <h:inputSecret  required="true" id = "password" value="#{suggestionBoxBean.password}" >
                                                                            <f:validateLength  minimum="5"/>
                                                                        </h:inputSecret>
                                                                        <h:message styleClass="error" for="password" />
                                                                    </td>
                                                                </tr>
                                                                <tr> 
                                                                    <td><b>Sesso: </b></td>
                                                                    <td>
                                                                        <h:outputText value="#{suggestionBoxBean.sesso}" rendered = "#{suggestionBoxBean.render}"/>
                                                                        <h:selectOneMenu value="#{suggestionBoxBean.sesso}" rendered = "#{suggestionBoxBean.birth}">
                                                                            <f:selectItem id="item1" itemLabel="M" itemValue="M" />
                                                                            <f:selectItem id="item2" itemLabel="F" itemValue="F" />
                                                                        </h:selectOneMenu>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td><b>Data di nascita: </b></td>
                                                                    <td>
                                                                        <h:outputText value="#{suggestionBoxBean.dataNascita}" rendered = "#{suggestionBoxBean.render}"/>
                                                                        <rich:calendar id="data"
                                                                                       value="#{suggestionBoxBean.dN}"
                                                                                       datePattern="dd/MM/yyyy HH:mm"
                                                                                       enableManualInput="true"
                                                                                       cellWidth="24px"
                                                                                       cellHeight="22px"
                                                                                       style="width:200px"
                                                                                       rendered = "#{suggestionBoxBean.birth}"
                                                                                       />
                                                                        <h:message styleClass="error" for="data"/>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td><b>Luogo di nascita: </b></td>
                                                                    <td>
                                                                        <h:outputText value="#{suggestionBoxBean.luogoNascita}" rendered="#{suggestionBoxBean.render}"/>
                                                                        <h:inputText id="luogo" required="true" value="#{suggestionBoxBean.luogoNascita}" rendered="#{suggestionBoxBean.birth}"/>
                                                                        <h:message styleClass="error" for="luogo" />
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td><b>Indirizzo: </b></td>
                                                                    <td>
                                                                        <h:outputText value="#{suggestionBoxBean.indirizzo}" rendered="#{suggestionBoxBean.render}"/>
                                                                        <h:inputText id="indirizzo" required="true" value="#{suggestionBoxBean.indirizzo}" rendered="#{suggestionBoxBean.birth}"/>
                                                                        <h:message styleClass="error" for="indirizzo" />
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td><b>CAP: </b></td>
                                                                    <td>
                                                                        <h:outputText value="#{suggestionBoxBean.cap}" rendered="#{suggestionBoxBean.render}"/>
                                                                        <h:inputText id="cap" required="true" value="#{suggestionBoxBean.cap}" rendered="#{suggestionBoxBean.birth}"/>
                                                                        <h:message styleClass="error" for="cap" />
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td><b>E-Mail: </b></td>
                                                                    <td>
                                                                        <h:inputText id="email" value="#{suggestionBoxBean.email}">
                                                                            <f:validator validatorId="EmailValidator"/>
                                                                        </h:inputText>
                                                                        <h:message styleClass="error" for="email"/>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td><b>Telefono: </b></td>
                                                                    <td>
                                                                        <h:inputText id="telefono" value="#{suggestionBoxBean.telefono}">
                                                                            <f:validateLongRange minimum="0" />
                                                                        </h:inputText>
                                                                        <h:message styleClass="error" for="telefono"/>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td><b>*Genitore: </b></td>
                                                                    <td>
                                                                        <h:inputText  required="true" id="input_genitore" value="#{suggestionBoxBean.genitore}">
                                                                            <f:validator validatorId="NoSuggestValidator"/>
                                                                        </h:inputText>
                                                                        <h:message styleClass="error" for="input_genitore"/>
                                                                        <rich:suggestionbox  for="input_genitore"
                                                                                             suggestionAction="#{pazientiACBean.autocompleteGenitore}"
                                                                                             fetchValue="#{genitore.id} #{genitore.nome} #{genitore.cognome}"
                                                                                             param="#{suggestionBoxBean.id}"
                                                                                             var="genitore"
                                                                                             height="200"
                                                                                             width="300" >

                                                                            <h:column>
                                                                                <h:outputText value="#{genitore.id}"/>
                                                                            </h:column>
                                                                            <h:column>
                                                                                <h:outputText value="#{genitore.nome}" />
                                                                            </h:column>
                                                                            <h:column>
                                                                                <h:outputText value="#{genitore.cognome}"/>
                                                                            </h:column>
                                                                            <h:column>
                                                                                <h:outputText value="#{genitore.dataNascita}"/>
                                                                            </h:column>
                                                                        </rich:suggestionbox>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td><b>Medico: </b></td>
                                                                    <td>
                                                                        <h:outputText value="#{loginBean.nome} #{loginBean.cognome}" />
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td><b>*Capo villaggio: </b></td>
                                                                    <td>
                                                                        <h:inputText required = "true" id = "input_capo" value="#{suggestionBoxBean.capoVillaggio}">
                                                                            <f:validator validatorId="NoSuggestValidator"/>
                                                                        </h:inputText>
                                                                        <h:message styleClass="error" for="input_capo"/>
                                                                        <rich:suggestionbox  for="input_capo"
                                                                                             suggestionAction="#{pazientiACBean.autocompleteCapo}"
                                                                                             fetchValue="#{result.id} #{result.nome} #{result.cognome}"
                                                                                             var="result"
                                                                                             height="200"
                                                                                             width="300" >

                                                                            <h:column>
                                                                                <h:outputText value="#{result.id}"/>
                                                                            </h:column>
                                                                            <h:column>
                                                                                <h:outputText value="#{result.nome}" />
                                                                            </h:column>
                                                                            <h:column>
                                                                                <h:outputText value="#{result.cognome}"/>
                                                                            </h:column>
                                                                            <h:column>
                                                                                <h:outputText value="#{result.dataNascita}"/>
                                                                            </h:column>
                                                                        </rich:suggestionbox>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td>
                                                                        <h:commandButton value = "Registra" action="#{suggestionBoxBean.register}" rendered= "#{suggestionBoxBean.render}"/>
                                                                        <h:commandButton value = "Registra il nuovo nato" action="#{suggestionBoxBean.birthRegister}" rendered= "#{suggestionBoxBean.birth}"/>
                                                                    </td>
                                                                    <td>
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                        </td>
                                                    </tr>                                
                                                </table>
                                            </h:panelGroup>
                                        </h:panelGroup>
                                    </a4j:form>
                                    <h:panelGroup id ="fu">
                                        <h:form rendered="#{suggestionBoxBean.render || suggestionBoxBean.birth}">
                                            <rich:fileUpload fileUploadListener="#{suggestionBoxBean.listener}"
                                                             maxFilesQuantity="#{suggestionBoxBean.uploadsAvailable}"
                                                             id="upload"
                                                             listWidth="100%"
                                                             listHeight="100%"
                                                             immediateUpload="#{suggestionBoxBean.autoUpload}"
                                                             acceptedTypes="jpg, gif, png, bmp" allowFlash="#{suggestionBoxBean.useFlash}"  >
                                                <a4j:support event="onuploadcomplete"  reRender="foto" />
                                            </rich:fileUpload> 
                                        </h:form>

                                    </h:panelGroup>
                                </div>
                            </div>                           
                        </div>
                        <!-- end #content -->
                        <div id="sidebar">
                            <ul>
                                <li>
                                    <jsp:include page="../subviews/language_chooser.jsp"/>
                                </li>
                                <li>
                                    <jsp:include page="../subviews/side_reserved_menu.jsp"/>
                                </li>
                            </ul>
                        </div>
                        <!-- end #sidebar -->
                        <div style="clear: both;">&nbsp;</div>
                    </div>
                </div>
                <!-- end #page -->
                <div id="footer-bgcontent">
                    <div id="footer">
                        <p>Copyright &copy; 2011 <a href="#">Mamesoft</a>
                            Progetto Programmazione per il web A.A.2011/2012</p>
                    </div>
                </div>
                <!-- end #footer -->
            </div>
        </body>
    </html>
</f:view>
